var url = serverPre + "/manager/yzt/v1/abnormal";

var bsConf = {

    queryFormId: "abnormal-query-form",

    createFormId: "abnormal-create-form",

    updateFormId: "abnormal-update-form",

    tableID: "id",

    queryCols: 3,

    queryFloat: "right",

    voName: "abnormalInfo",
    initData: true,
    queryConfigs:                   //页面头部查询form
        [
            {
                type: 'select',
                label: '异常类型',
                name: 'abnormalType',
                default: '3',
                verify: '',
                cols: [[0, '客户信息异常'], [1, '客户信息不一致']]
            },
            {
                type: 'text',
                label: '客户姓名',
                name: 'customerName',
                default: '',
                verify: ''
            },
            {
                type: 'select',
                label: '证件类型',
                name: 'idCardType',
                default: '10',
                verify: '',
                cols: [[1, '身份证'], [2, '护照'], [3, '港澳台通行证'], [4, '外国人永久居留证'], [5, '军官证']]
            },
            {
                type: 'text',
                label: '证件号码',
                name: 'idCardNo',
                default: '',
                verify: ''
            },
            {
                type: 'select',
                label: '处理状态',
                name: 'status',
                default: '10',
                verify: '',
                cols: [[0, '待处理'], [1, '已处理'], [2, '无需处理']]
            },
            {
                type: 'datetime',
                label: '创建时间',
                name: 'createTimeStart',
                default: '',
                verify: ''
            },
            {
                type: 'datetime',
                label: '至',
                name: 'createTimeEnd',
                default: '',
                verify: ''
            }
        ],

    //列表内容
    tableCols: [
        {type: 'checkbox'}
        , {field: 'id', title: '序号', type: 'numbers'}
        , {field: 'abnormalType', width: '20%', title: '异常类型'}
        , {field: 'customerName', width: '10%', title: '客户姓名'}
        , {field: 'idCardType', width: '10%', title: '证件类型'}
        , {field: 'idCardNo', width: '20%', title: '证件号码'}
        , {field: 'createTime', width: '20%', title: '创建时间'}
        , {field: 'status', width: '10%', title: '处理状态'}
        , {
            fixed: 'right', width: '10%', title: '异常详情', templet: function (d) {
                return "" +
                    "  <button dataid='" + d.id + "' onclick=\"showDetail('" + d.id + "');\" class=\"layui-btn layui-btn-sm bs-button-update\">查看详情</button>\n" +
                    "";
            }
        }
    ],
    enableBtns: true,
};

function showDetail(id) {
    $.ajax({
        type: 'get',
        url: serverPre + "/manager/yzt/v1/abnormal/detail?id=" + id,
        dataType: 'json',
        headers: {"token": getCookie("token")},
        async: false,
        cache: false,
        success: function (result) {
            var tablec = "<table class=\"layui-table\">\n" +
                "  <colgroup>\n" +
                "    <col width=\"40\">\n" +
                "    <col width=\"40\">\n" +
                "    <col width=\"60\">\n" +
                "    <col width=\"60\">\n" +
                "    <col width=\"60\">\n" +
                "    <col>\n" +
                "  </colgroup>\n" +
                "  <thead>\n" +
                "    <tr>\n" +
                "      <th>客户号</th>\n" +
                "      <th>客户姓名</th>\n" +
                "      <th>证件类型</th>\n" +
                "      <th>证件号码</th>\n" +
                "      <th>子系统标识</th>\n" +
                "    </tr> \n" +
                "  </thead>\n" +
                "  <tbody>\n";
            if (result.data.list.length > 0) {
                for (var i = 0; i < result.data.list.length; i++) {
                    var v = result.data.list[i];
                    tablec += "<tr><td>" + v['customerNo'] + "</td><td>" + v['customerName'] + "</td><td>" + v['idCardType'] + "</td><td>" + v['idCardNo'] + "</td><td>" + v['subSystemSign'] + "</td></tr>\n";
                }
            } else {
                tablec += "<tr><td colspan='5' style='text-align: center'>无数据</td></tr> "
            }
            tablec += "</tbody></table>";
            var content = "<div style='margin: 10px;'>" +
                "<blockquote class=\"layui-elem-quote\">异常客户信息详情：</blockquote>" + tablec +
                "</div>";
            layer.open({
                type: 1,
                title: '异常详情信息',
                shadeClose: true,
                shade: false,
                maxmin: true,
                content: content,
                area: ['80%', '70%']
            });
        }
    });

}

function updateSts(obj, status) {
    if (obj.className.indexOf("layui-btn-disabled") < 0) {
        var s = $(this).className;
        var checkStatus = table.checkStatus('id'),
            data = checkStatus.data;
        if (data.length === 0) {
            layer.msg('请选择一条数据');
            return;
        } else if (data.length > 1) {
            layer.msg('只允许处理一条数据');
            return;
        } else if (data[0].status != "待处理") {
            layer.msg('当前状态已经是终态不可修改');
            return;
        }
        layer.confirm('确定处理这条数据吗?', function (index) {
            var id = data[0].id;
            $.ajax({
                type: 'get',
                url: serverPre + "/manager/yzt/v1/abnormal/updateSts?id=" + id + "&&status=" + status,
                dataType: 'json',
                headers: {"token": getCookie("token")},
                async: false,
                cache: false,
                success: function (result) {
                    if (result.code == 0) {
                        layer.msg("处理成功", {
                            icon: 1,
                            time: 1000
                        });
                        queryData(url, pageObj.curr, pageObj.limit);
                    } else {
                        layer.msg("处理失败", {
                            time: 1000
                        });
                    }
                }
            });

        });
    }
}

function abnormal_search() {
    $("#abnormal-query-form").toggle()
}

